package com.devin.controller;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 *  
 *  @author devin
 *  @date 2020-04-21 13:12
 *  @version 1.0.2
*/
@Controller
public class LogController {

    @ResponseBody
    @RequestMapping("/log")
    public void getLog(HttpServletResponse response) throws IOException {
        File file = new File("/home/jet/oss.log");
        FileInputStream in = new FileInputStream(file);
        ServletOutputStream out = response.getOutputStream();
        byte buffer[] = new byte[1024];
        int len = 0;
        System.out.println("s");
        while ((len = in.read(buffer)) > 0) {
            // 输出缓冲区内容到浏览器，实现文件下载
            out.write(buffer, 0, len);
        }
    }
}
